<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	private $_acl = null;
	
	protected function _initSession(){
		Zend_Session::start();
	}
	
	protected function _initLocale(){
		$locale = new Zend_Locale('vi_VN');
		Zend_Registry::set('Zend_Locale',$locale);
		$front = Zend_Controller_Front::getInstance();
	}
	
    protected function _initAutoload() {
        $modelLoader = new Zend_Application_Module_Autoloader(array(
                        'namespace' => '',
                        'basePath' => APPLICATION_PATH.'/modules/default'));
        
       if(Zend_Auth::getInstance()->hasIdentity()) {
			Zend_Registry::set('role',Zend_Auth::getInstance()->getStorage()->read()->QuyenHan);
		} else {
			Zend_Registry::set('role', 'guests');
		}
		
        $this->_acl = new Model_LibraryAcl;
        $this->_auth = Zend_Auth::getInstance();
        
        $fc = Zend_Controller_Front::getInstance();
        $fc->registerPlugin(new Plugin_AccessCheck($this->_acl));
        return $modelLoader;
    }
	
	function _initViewHelpers() {
		$view = new Zend_View();
		$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
        $viewrenderer = new Zend_Controller_Action_Helper_ViewRenderer();
        $viewrenderer->setView($view);
        Zend_Controller_Action_HelperBroker::addHelper($viewrenderer);
		
		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		$view = $layout->getView();
		
		$view->setHelperPath(APPLICATION_PATH.'\helpers', 'Zend_View_Helper');
		ZendX_JQuery::enableView($view);
		/* Zend_Dojo::enableView($view); */
		$view->doctype('XHTML1_STRICT');
		$view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
						->appendName('description', 'Using view helpers in Zend_view');
						
						
		$view->headTitle()->setSeparator(' - ')
			 ->headTitle('Quản lý học viên');
		
		$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
		$navContainer = new Zend_Navigation($navContainerConfig);
		$view->navigation($navContainer)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));
	}
	protected function _initLogs()
	{
		$logger = new Zend_Log();
		$fireBugWriter = new Zend_Log_Writer_Firebug();
		$logger->addWriter($fireBugWriter);
		Zend_Registry::set('logger',$logger);
	}
	
}

